package DoublePointer;

public class DoublePointer1_twoSum {
    public static void main(String[] args) {
        int[] number = {2,7,11,15};
        int target = 9;
        //定义两个指针
        int index_first = 0;
        int index_end = number.length - 1;
        while (index_first<index_end){
            if (target == number[index_first]+number[index_end]){
                break;
            }else if(target >number[index_first]+number[index_end]){
                index_first++;
            }else {
                index_end--;
            }
        }
        //将得到的结果+1，表示其位置
        int  first = index_first + 1;
        int end = index_end + 1;
        System.out.println("index1:"+ first);
        System.out.println("index2:"+ end);
    }
}
